<?php

namespace app\backend\models;

use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

class BigWheelPrizeModel extends BaseModel
{
    const table = 'activity_bigwheel_prize';

    const _field = ['*'];

    static $_instance;

    public static function getInstance()
    {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * 获取数据
     * @param $condition
     * @param array $field
     * @return array
     */
    public  function getList($condition, array $field = self::_field)
    {
        return DB::table(self::table)->select($field)->where($condition)->get()->toArray();
    }

    /**
     * 获取数据数量
     * @param $condition
     * @param array $field
     * @return int
     */
    public  function getCount($condition, array $field = self::_field)
    {
        return DB::table(self::table)->select($field)->where($condition)->count();
    }

    /**
     * 计算中奖概率
     * @param $condition
     * @param array $field
     * @return int
     */
    public  function getChanceSum($condition)
    {
        return DB::table(self::table)->where($condition)->Sum('win_chance');
    }


    /**
     * 获取数据
     * @param $condition
     * @param $field
     * @return
     */
    public  function getInfo($condition, array $field = self::_field)
    {
        return DB::table(self::table)->select($field)->where($condition)->first();
    }

    /**
     * 保存数据
     * @param $data
     * @return bool
     */
    public function addSave($data)
    {
        if (!$data){
            return '';
        }
        $data['create_time'] = time();
        return DB::table(self::table)->insert($data);
    }

    /**
     * 修改数据
     * @param $condition
     * @param $data
     * @return int|string
     */
    public function updateSave($condition,$data)
    {
        if (!$condition||!$data){
            return '';
        }
        $data['update_time'] = time();
        return DB::table(self::table)->where($condition)->update($data);
    }

    /**
     * 删除数据
     * @param $condition
     * @return int|string
     */
    public function deleteData($condition)
    {
        if (!$condition){
            return '';
        }
        return DB::table(self::table)->where($condition)->delete();
    }


}
